package com.lintf.starter.central.auth;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.convert.DurationUnit;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

@ConfigurationProperties(prefix = "central.auth")
public class CentralAuthProperties {

    private String clientId;

    private String clientSecret;

    private String tokenUrl;

    private String scope = "default";

    private CacheType cacheType = CacheType.MEMORY;

    @DurationUnit(ChronoUnit.SECONDS)
    private Duration tokenTtl = Duration.ofMinutes(30);

    @DurationUnit(ChronoUnit.SECONDS)
    private Duration refreshWindow = Duration.ofMinutes(5);

    // Getters and Setters
    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getClientSecret() {
        return clientSecret;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    public String getTokenUrl() {
        return tokenUrl;
    }

    public void setTokenUrl(String tokenUrl) {
        this.tokenUrl = tokenUrl;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public CacheType getCacheType() {
        return cacheType;
    }

    public void setCacheType(CacheType cacheType) {
        this.cacheType = cacheType;
    }

    public Duration getTokenTtl() {
        return tokenTtl;
    }

    public void setTokenTtl(Duration tokenTtl) {
        this.tokenTtl = tokenTtl;
    }

    public Duration getRefreshWindow() {
        return refreshWindow;
    }

    public void setRefreshWindow(Duration refreshWindow) {
        this.refreshWindow = refreshWindow;
    }

    @Override
    public String toString() {
        return "CentralAuthProperties{" +
                "clientId='" + clientId + '\'' +
                ", clientSecret='" + clientSecret + '\'' +
                ", tokenUrl='" + tokenUrl + '\'' +
                ", scope='" + scope + '\'' +
                ", cacheType=" + cacheType +
                ", tokenTtl=" + tokenTtl +
                ", refreshWindow=" + refreshWindow +
                '}';
    }

    public enum CacheType {
        MEMORY, REDIS, NONE
    }
}